<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\Relations\belongsTo;

/**
 * @property int $id 
 * @property int $goods_id 
 * @property string $name 
 * @property float $price 
 * @property float $original_price 
 * @property int $integral 
 * @property int $stock 
 * @property float $weight 
 * @property string $bar_code 
 * @property int $sales 
 * @property array $properties
 * @property string $sku_hash 
 * @property string $picture 
 */
class GoodsSku extends Model
{
    public $timestamps = false;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'goods_sku';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'goods_id' => 'integer', 'price' => 'float', 'original_price' => 'float', 'integral' => 'integer', 'stock' => 'integer', 'weight' => 'float', 'sales' => 'integer', 'properties' => 'array'];

    /**
     * 商品关联模型
     *
     * @return belongsTo
     */
    public function goods(): BelongsTo
    {
        return $this->belongsTo(Goods::class, 'goods_id');
    }

    /**
     * 封面图片获取器
     *
     * @param $value
     * @return string
     */
    public function getPictureAttribute($value)
    {
        return gConfig('ali_oss_domain') . $value;
    }
}